using System.Web.UI.WebControls;
using TemplateFoundation.PageTypes;

namespace TemplateFoundation.PageTypeIcons.IconHandlers {

    /// <summary>
    /// <para>The base class for all IconHandlers.</para>
    /// </summary>
    public abstract class IconHandlerBase {

        #region Properties
        /// <summary>
        /// <para>Gets the url to the handler icon.</para>
        /// </summary>
        /// <value>The URL to the icon image.</value>
        protected virtual string IconUrl {
            get;
            set;
        }

        /// <summary>
        /// <para>Gets the tooltip text for the icon.</para>
        /// </summary>
        /// <value>The tooltip text.</value>
        protected virtual string IconToolTip {
            get;
            set;
        }        
        #endregion

        #region Methods
        /// <summary>
        /// <para>Gets the icon to use for the current page node in the tree.</para>
        /// <para>If the handler doesn't match the given page, this method should return null.</para>
        /// </summary>
        /// <param name="page">The current page in the page tree.</param>
        /// <returns>
        /// An <see cref="Image"/> to use as the icon for the current node if handler match the page; otherwise <c>null</c>.
        /// </returns>
        public virtual Image GetIcon(PageTypeBase page) {
            if (IsMatch(page)) {
                Image icon = new Image();
                icon.ImageUrl = IconUrl;
                icon.AlternateText = icon.ToolTip = IconToolTip;
                return icon;
            }
            return null;
        }

        /// <summary>
        /// <para>Determines whether the specified page is match for the current tree icon handler and an icon should be returned.</para>
        /// </summary>
        /// <param name="page">The current page in the page tree to check for match against.</param>
        /// <returns>
        /// 	<c>true</c> if the specified page is match and an icon should be returned; otherwise, <c>false</c>.
        /// </returns>
        public abstract bool IsMatch(PageTypeBase page);
        #endregion
    }
}